package com.glsc.ngateway.common.base.converter.platform;

import com.alibaba.excel.util.CollectionUtils;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.FlowFormEquipmentModifyVirtualDeviceDetail;
import com.glsc.ngateway.common.base.domainmapper.FlowFormEquipmentModifyVirtualDeviceDetailMapper;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.equipment.domainDto.FlowFormEquipmentModifyVirtualDeviceDetailDto;
import org.apache.logging.log4j.util.Strings;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * FlowFormEquipmentModifyVirtualDeviceDetail
 *
 * @author xuchang
 */
public class FlowFormEquipmentModifyVirtualDeviceDetailConverter extends AbstractFlowFormDataConverter {
    public static FlowFormEquipmentModifyVirtualDeviceDetailDto do2Dto(FlowFormEquipmentModifyVirtualDeviceDetail modifyVirtualDeviceDetail) {
        if (Objects.isNull(modifyVirtualDeviceDetail)) {
            return null;
        }
        FlowFormEquipmentModifyVirtualDeviceDetailDto applyDto = FlowFormEquipmentModifyVirtualDeviceDetailMapper.INSTANCE.domain2dto(modifyVirtualDeviceDetail);
        applyDto.setIpList(Strings.isBlank(modifyVirtualDeviceDetail.getIpListStr()) ? new ArrayList<>(0)
                : Arrays.stream(modifyVirtualDeviceDetail.getIpListStr().split(",")).collect(Collectors.toList()));
        applyDto.setIpListModified(Strings.isBlank(modifyVirtualDeviceDetail.getIpListModifiedStr()) ? new ArrayList<>(0)
                : Arrays.stream(modifyVirtualDeviceDetail.getIpListModifiedStr().split(",")).collect(Collectors.toList()));
        return applyDto;
    }

    public static List<FlowFormEquipmentModifyVirtualDeviceDetailDto> do2Dto(List<FlowFormEquipmentModifyVirtualDeviceDetail> modifyVirtualDeviceDetailList) {
        return CollectionUtils.isEmpty(modifyVirtualDeviceDetailList) ? java.util.Collections.emptyList() : modifyVirtualDeviceDetailList.stream().map(FlowFormEquipmentModifyVirtualDeviceDetailConverter::do2Dto).collect(Collectors.toList());
    }

    public static FlowFormEquipmentModifyVirtualDeviceDetail dto2Do(FlowFormEquipmentModifyVirtualDeviceDetailDto modifyVirtualDeviceDetailDto) {
        if (Objects.isNull(modifyVirtualDeviceDetailDto)) {
            return null;
        }
        FlowFormEquipmentModifyVirtualDeviceDetail apply = FlowFormEquipmentModifyVirtualDeviceDetailMapper.INSTANCE.dto2domain(modifyVirtualDeviceDetailDto);
        apply.setIpListStr(CollectionUtils.isEmpty(modifyVirtualDeviceDetailDto.getIpList()) ? Strings.EMPTY
                : String.join(",", modifyVirtualDeviceDetailDto.getIpList()));
        apply.setIpListModifiedStr(CollectionUtils.isEmpty(modifyVirtualDeviceDetailDto.getIpListModified()) ? Strings.EMPTY
                : String.join(",", modifyVirtualDeviceDetailDto.getIpListModified()));
        return apply;
    }

    public static List<FlowFormEquipmentModifyVirtualDeviceDetail> dto2Do(List<FlowFormEquipmentModifyVirtualDeviceDetailDto> modifyVirtualDeviceDetailDtoList) {
        return CollectionUtils.isEmpty(modifyVirtualDeviceDetailDtoList) ? java.util.Collections.emptyList() : modifyVirtualDeviceDetailDtoList.stream().map(FlowFormEquipmentModifyVirtualDeviceDetailConverter::dto2Do).collect(Collectors.toList());
    }

}
